<template>
  <div class="
    white-module">
    <div class="scholl-tabs">
      <!--
      <el-button class="tabs-btn" type="primary">添加课程</el-button>
      -->
      <el-tabs v-model="activeName">
        <el-tab-pcxane label="课程列表" name="first"></el-tab-pcxane>
      </el-tabs>
    </div>
    <el-row class="search-module" >
      <el-form :inline="true" :model="dataForm" @keyup.enter="getDataList()" style="width: 100%">
      <el-col class="search-left" :span="18">
        课程名称：<el-input  v-model="dataForm.name" placeholder="请输入课程名称" />
        <span class="interval"></span>
      </el-col>
      <el-col class="right-btn" :span="6">
        <el-button type="primary"  @click="getDataList()" >查询</el-button>
        <el-button type="default">重置</el-button>
      </el-col>
      </el-form>
    </el-row>
    <div class="global-table">
      <el-table
        :data="dataList"
        :header-cell-style="{
          background: '#F5F7FA',
          color: '#333',
        }"
        style="width: 100%"
      >
        <el-table-column prop="title" label="课程名称" />
        <el-table-column prop="categoryName" label="课程分类" />
        <!--
        <el-table-column prop="source" label="来源" />
        <el-table-column prop="status" label="状态" >
          <template v-slot="scope">
            <el-tag v-if="scope.row.type === 1" size="small" >已发布</el-tag>
            <el-tag v-else size="small" type="danger">未发布</el-tag>
          </template>
        </el-table-column>
        -->
        <el-table-column prop="exportDate" label="到期时间">
          <template v-slot="scope">
            <!--IsExpire==true 显示黄色-->
            <div v-if="scope.row.isExpire==1" size="small" style="color: #e6a23c;">{{scope.row.exportDate}}</div>
            <div v-else-if="scope.row.isExpire==2" size="small" style="color: red;">{{scope.row.exportDate}}</div>
            <div v-else>{{scope.row.exportDate}}</div>
          </template>
        </el-table-column>
        <el-table-column label="操作" width="300">
          <template #default="scope">
            <el-button type="text" size="small" @click="toDetail(scope.row)"> 查看详情 </el-button>
            <el-button type="text" size="small" @click="toPlan(scope.row)" v-if="scope.row.isExpire !=2 "> 查看教案 </el-button>
            <el-button type="text" size="small" @click="evaluation(scope.row)" v-if="(userInfo.type===3) && scope.row.isExpire !=2"> 课程评价 </el-button>
            <!--只有老师能快速上课-->
            <el-button type="text" size="small" @click="showDialog(scope.row)" v-if="(userInfo.type===1 || userInfo.type===3) && scope.row.isExpire !=2"> 快速上课 </el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>

    <el-row class="global-pagination" >
      <el-col :span="8" class="total"> 共搜索 {{total}} 条数据 </el-col>
      <el-col :span="16">
        <el-pagination
          background
          layout="  prev, pager, next, jumper"
          :current-page="page"  :page-sizes="[10, 20, 50, 100]" :page-size="limit"
          :total="total"
          :small="false"
          :disabled="false"
          @size-change="query"
          @current-change="pageCurrentChangeHandle"
        />
      </el-col>
    </el-row>

    <!--快速上课弹窗-->
    <el-dialog title="选择课堂" v-model="showDialogFlag">
      <el-form :model="updateForm">
        <el-form-item label="课堂" :label-width="formLabelWidth">
          <el-select v-model="selectClass" placeholder="请选择课堂">
            <el-option label="默认课堂" value="默认课堂">默认课堂</el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="showDialogFlag = false">取 消</el-button>
        <el-button type="primary" @click="startClass()">确 定</el-button>
      </div>
    </el-dialog>

    <!--课程评价弹窗-->
    <el-dialog title="课程评价" v-model="evaluationDialogFlag">
      <el-form :model="updateForm">
        <el-form-item label="课程评价" :label-width="formLabelWidth">
          <el-input
              type="textarea"
              rows="3"
              placeholder="请填写评价"
              v-model="updateForm.evaluation"
          ></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer" style="padding-left: 120px;">
        <el-button @click="evaluationDialogFlag = false">取 消</el-button>
        <el-button type="primary" @click="saveEvaluation()">确 定</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script lang="ts" >
import { defineComponent, reactive, toRefs,ref } from "vue";
import {getCache, getUserInfo, setCache} from "@/utils/cache";
import listService from "@/service/listService";
import baseService from "@/service/baseService";
import router from "@/router";

export default defineComponent({
  setup() {


    const state = reactive({
      getDataListURL: "/fii/front/fiicourse/page",
      getDataListIsPage: true,
      deleteURL: "/pay/order",
      deleteIsBatch: true,
      dataForm: {
        orderId: "",
        status: "",
        name: ""
      }
    });
    return { ...listService(state), ...toRefs(state) };
  },

  data() {
    return {
      showDialogFlag: false,
      evaluationDialogFlag: false,
      updateForm: {
        id: null,
        evaluation: ''
      },
      selectClass: '默认课堂',
      formLabelWidth: '120px',
      userInfo: getCache('CacheToken', { isSessionStorage: true }, {})
    };
  },

  methods: {
    payHandle(orderId: string) {
      //window.open(`${app.api}/pay/alipay/webPay?orderId=` + orderId);
    },

    clearForm(){
      //this.dataForm.like_schoolName = '';
    },

    showDialog(entity: any){
      this.showDialogFlag = true;
      this.updateForm.id = entity.id;
      //this.updateForm.schoolName = entity.schoolName;
    },

    /**
     * 查看课纲与教案
     */
    toPlan(entity: any){
      router.push({path: "/course/plan", query: {id: entity.id}});
    },

    /**
     * 查看详情
     */
    toDetail(entity: any){
      router.push({path: "/course/detail", query: {id: entity.id}});
    },

    /**
     * 快速上课
     */
    startClass() {
      //type=2标准学习台
      router.push({path: "/classroom/study", query: {id: this.updateForm.id,type: 2}});
    },

    /**
     * 课程评价
     */
    evaluation(entity: any){
      this.evaluationDialogFlag = true;
      this.updateForm.id = entity.id;
    },

    /**
     * 保存评价
     */
    saveEvaluation(){
      this.evaluationDialogFlag = false
      baseService
          .post("/fii/front/fiicourse/saveSuggest", {courseId: this.updateForm.id, suggest: this.updateForm.evaluation})
          .then((res) => {
                if (res.code === 0) {
                }
              }
          );

    }

  }
});
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="scss" >
.search-module {
  display: flex;
  justify-content: space-between;
  padding: 0px 20px 0px 20px;
  margin-top: 10px;
  .interval {
    padding: 0px 15px;
  }

  .search-left {
    color: #333333;
    text-align: left;
  }
  .right-btn {
    text-align: right;
  }
}
.global-table {
  margin-top: 15px;
  padding: 0px 20px;
}

.popper-menu {
  border: 0px !important;
  .el-menu {
    padding: 0px !important;
    background-color: #008fd1 !important;
    .el-menu-item-group__title {
      padding: 0px;
    }
    .el-menu-item:hover {
      background-color: #ffffff !important;
      color: #00a0e9;
    }

    .el-menu-item.is-active {
      background-color: #ffffff !important;
    }
  }
}
</style>
